$(function () {

    list()
})



function add() {
    location.href = "./create.html"
}
function edit() {
    location.href = "./create.html"
}
function cancel() {
    location.href = "./index.html"
}



function list(datas) {
    $.get(`http://localhost:8000/blog`, data => {

        if (datas) {
            data = datas
        }
        $('.row').remove()
        data.forEach(item => {
            let html = `
        <tr class='row'>
    <td>${item.id}</td>
    <td>${item.bt}</td>
    <td>${item.zy}</td>
    <td>${item.nr}</td>
    <td>${item.fl}</td>
    <td>${item.zz}</td>
    <td>${item.gx}</td>
    <td>
        <input type="button" value="编辑" onclick="edit(${item.id})">
        <input type="button" value="删除" onclick="deleted(${item.id})">
    </td>
</tr>
              
        `
            $('#all').append(html)

        })
    });

}


function find() {
    let keyword = $('#keywod').val()

    $.post(`http://localhost:8000/blog?keyword=${keyword}`, data => {

        list(data)


    })
}



function deleted(id) {
    let obj = { id }
    $.post(`http://localhost:8000/deleted`, obj, () => {

        location.href = "./index.html"

    })

}


